package com.google.gwt.sample.stockwatcher.server;

import com.google.gwt.sample.stockwatcher.client.StockEdit;
import com.google.gwt.sample.stockwatcher.client.StockPrice;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

import org.hibernate.Session;

import util.HibernateUtil;

@SuppressWarnings("serial")
public class StockEditImpl extends RemoteServiceServlet implements StockEdit{
	public StockPrice getPrice(StockPrice editPrice){
		StockPrice news=new StockPrice();
		int id =editPrice.getId();
		String name =editPrice.getName();
		String sername =editPrice.getSername();
		String phone =editPrice.getPhone();
		news.setId(id);
		news.setName(name);
		news.setPhone(phone);
		news.setSername(sername);
		
		Session sess = HibernateUtil.getSessionFactory().getCurrentSession();
		sess.beginTransaction();
	//	Object book = (StockPrice) sess.load(StockPrice.class, id);
		sess.update(news);
		sess.getTransaction().commit();
		sess.close();
		
		/*	Statement statement = null;
			Connection con = null;
			try {
			con = DriverManager.getConnection("jdbc:postgresql://127.0.0.1:5433/postgres", "postgres", "hr");
			statement = con.createStatement();
			statement.executeUpdate("UPDATE \"manual\" SET surname='"+sername+"', name='"+name+"', phone='"+phone+"' where id='"+id+"'");
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			*/
			return null;
		
	}
}